package com.hj.system.system.service.impl;

import com.hj.system.system.dao.UserFingerDao;
import com.hj.system.system.service.UserFingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hj.system.system.domain.UserFingerDO;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hj.system.base.utils.PageUtils;


@Service
public class SysUserFingerprintServiceImpl implements UserFingerService {
    @Autowired
    private UserFingerDao userFingerDao;

    @Override
    public UserFingerDO get(Long id) {
        return userFingerDao.get(id);
    }

    @Override
    public PageUtils list(Map<String, Object> map) {
        return PageUtils.getPageUtils(userFingerDao, map);
    }

    @Override
    public int save(UserFingerDO sysUserFingerprint) {
        Map<String, Object> param = new HashMap<>();
        param.put("userId", sysUserFingerprint.getUserId());
        param.put("type", sysUserFingerprint.getType());
        List<UserFingerDO> fingerDOS = userFingerDao.list(param);
        if(fingerDOS.isEmpty()){
            return userFingerDao.save(sysUserFingerprint);

        }else {
            UserFingerDO userFingerDO = fingerDOS.get(0);
            userFingerDO.setFinger(sysUserFingerprint.getFinger());
            return userFingerDao.update(userFingerDO);
        }
    }

    @Override
    public int update(UserFingerDO sysUserFingerprint) {
        return userFingerDao.update(sysUserFingerprint);
    }

    @Override
    public int remove(Long id) {
        return userFingerDao.remove(id);
    }

}
